﻿using DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ShopBack.Web.Controllers
{
    [Authorize]
    public class OrderController : Controller
    {
        // GET: Order
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 订单信息
        /// </summary>
        /// <param name="limit"></param>
        /// <param name="page"></param>
        /// <param name="Name"></param>
        /// <returns></returns>
        public ActionResult GetOrder(int limit, int page, string OrderId,string IsTake)
        {
            var total = 0;
            var list = OrderService.GetOrderMes(limit, page, OrderId,IsTake, out total).ToList();
            var list1 = list.Select(p => new { Id = p.Id, OrderId=p.OrderId, CustId=p.CustId, ProductName = p.ProductName, ShouName = p.ShouName, ToPrice = p.ToPrice, CustName = p.CustName, IsTake = p.IsTake, OrderTime = p.OrderTime.ToString("yyyy-MM-dd HH:mm:ss")});
            return Json(new { code = 0, msg = "", data = list1, count = total }, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <returns></returns>
        public ActionResult BatchDelShare(string Ids)
        {
            int a = OrderService.GetBatchDelByIds(Ids);
            if (a > 0)
            {
                return Json(new { Success = true, Message = "删除成功" });
            }
            else
            {
                return Json(new { Success = false, Message = "删除失败" });
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult ArtDel(int id)
        {
            int a = OrderService.GetArtDel(id);
            if (a > 0)
            {
                return Json(new { Success = true, Message = "删除成功" });
            }
            else
            {
                return Json(new { Success = false, Message = "删除失败" });
            }
        }

        /// <summary>
        /// 批量发货
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>

        public ActionResult DFaHuo(string Ids)
        {
            int a = OrderService.GetDFaHuos(Ids);
            if (a > 0)
            {
                return Json(new { Success = true, Message = "发货成功" });
            }
            else
            {
                return Json(new { Success = false, Message = "发货失败" });
            }
        }
        /// <summary>
        /// 发货
        /// </summary>
        /// <returns></returns>
        public ActionResult FaHuo(int id)
        {
            int a = OrderService.GetDFaHuo(id);
            if (a > 0)
            {
                return Json(new { Success = true, Message = "发货成功" });
            }
            else
            {
                return Json(new { Success = false, Message = "发货失败" });
            }
        }

        public ActionResult Detail(string Orderid)
        {
            var a = OrderDetailService.GetMsgOrderDetail(Orderid);
            return View(a);
        }

    }
}